<?php

    lt_include( PLOG_CLASS_PATH."class/plugin/pluginbase.class.php" );
    lt_include( PLOG_CLASS_PATH."class/plugin/pluginmanager.class.php" );
	lt_include( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
    lt_include( PLOG_CLASS_PATH."class/net/requestgenerator.class.php" );	
    
    /**
     * This plugin can be used to overwrite the CSS script in a template. 
	 * An alternative for template editing.
     */


    class PluginCssOverwrite extends PluginBase
    {
        var $pluginEnabled;
        var $rating;
        var $default;
        var $size;

        function PluginCssOverwrite( $source = '' )
        {
            $this->PluginBase();

            $this->id = "cssoverwrite";            
            $this->author = "Heriniaina Eugene (Madagascar)";
            $this->desc = "Allow bloggers to overwrite CSS";

            $this->locales = Array( "en_UK", "mg_MD");

            if($source == "admin" ) {
				$this->init();            
            } else {
				$this->registerNotification( EVENT_PROCESS_BLOG_TEMPLATE_OUTPUT );
            }
        }
        
		function init()
		{
            $this->registerAdminAction( "cssoverwriteconfig", "PluginCssOverwriteConfigAction" );
			$this->registerAdminAction( "updatecssoverwriteconfig", "PluginCssOverwriteUpdateConfigAction" );
            $this->registerAdminAction( "cssoverwrite", "PluginCssOverwriteAction" );
            $this->registerAdminAction( "updatecssoverwrite", "PluginCssOverwriteUpdateAction" );
			
			$menu =& Menu::getMenu();

		
			$this->addMenuEntry( "/menu/controlCenter/manageBlogTemplates", "CssOverwiteConfig", "admin.php?op=cssoverwriteconfig", "CssOverwiteConfig", false, false);

		}

		function register()
		{

	    }
	    
		function getPluginConfigurationKeys()
		{
			return( Array(
				Array( "name" => "plugin_cssoverwrite_enabled", "type" => "boolean" )
			));
		}

		function isEnabled()
	    {
	        return $this->pluginEnabled;
	    }

	    function getCSS()
	    {
	        return $this->csstext;
	    } 	       

		function process( $event, $params ) {
		    $blogSettings =& $params['blogInfo']->getSettings();
		    $this->pluginEnabled = $blogSettings->getValue( "plugin_cssoverwrite_enabled" );
		    $this->csstext = $blogSettings->getValue( "plugin_cssoverwrite_csstext" );

            if (!$this->pluginEnabled) { return true; }
			$content = $params["content"];
			$content = preg_replace('/<\/head>/i', '<style>' . $this->csstext . '</style></head>', $content);
			$params["content"] = $content;
		}

    }
?>
